package com.aat.dizena.web;

import com.aat.dizena.bean.Question;
import com.aat.dizena.service.QuestionService;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Iterator;

@RestController
@RequestMapping("qts")
public class QuestionController
{
    @Resource
    private QuestionService questionService;

    @GetMapping("list")
    public Iterator<Question> list()
    {
        Question m = questionService.findById(1L);
        if (m == null)
        {
            questionService.init();
        }
        return questionService.findAll();
    }

    @GetMapping("get/{id}")
    public Question get(@PathVariable("id") Long id)
    {
        return questionService.findById(id);
    }

    @GetMapping("title")
    public Page<Question> title(@RequestParam String str)
    {
        String field = "title";
        return questionService.search(field, str);
    }

    @GetMapping("content")
    public Page<Question> content(@RequestParam String str)
    {
        String field = "content";
        return questionService.search(field, str);
    }


}
